package collection;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
/**
 * Set接口:
 * 1.Set接口继承自Collection接口，为不可重复、没有下标的集合，有无序的也有有序的
 * 2.有两个常见的实现类:
 *   1)HashSet:不可重复、没有下标、无序
 *   2)LinkedHashSet:不可重复、没有下标、有序-------继承自HashSet
 */
public class HashSetDemo {
    public static void main(String[] args) {
     Set<Point> s=new HashSet<>();
     s.add(new Point (11,2));
     s.add(new Point (7,8));
     s.add(new Point (52,41));
     s.add(new Point (36,8));
     //是否重复是依据equals()和hashCode()来判断
     boolean b=s.add(new Point (11,2));
     System.out.println(b);//false
     System.out.println(s);//[(7,8), (36,8), (52,41), (11,2)]--------无序


     Set<Point> p=new LinkedHashSet<>();
     p.add(new Point (11,2));
     p.add(new Point (7,8));
     p.add(new Point (52,41));
     p.add(new Point (36,8));
     boolean b1=p.add(new Point (11,2));
     System.out.println(b1);
     System.out.println(p);//[(11,2), (7,8), (52,41), (36,8)]--------有序

    }
}
